package com.sdx.console.common.service;

import com.sdx.console.common.entity.BaseProvince;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.annotatoin.Sql;
import org.beetl.sql.core.query.LambdaQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName BaseDataService
 * @Description: No Description
 * @author: tanbaocai
 * @date: 2019/2/20 15:16
 */
@Service
@Transactional
public class BaseDataService {
	@Resource
	private SQLManager sqlManager;

	private final static String SQL = "common.baseProvince";

	public List<BaseProvince> getAllProvince() {
		List<BaseProvince> list = sqlManager.template(BaseProvince.class,null,"prov_id asc");
		return list;
	}

	public List<BaseProvince> getProvinces() {
		List<BaseProvince> list = sqlManager.select(SQL+".selectProvince",BaseProvince.class);
		return list;
	}

	public List<BaseProvince> getProv(Integer provStatus) {
		Map<String,Object> paramMap = new HashMap<>();
		if (provStatus!=null) {
			paramMap.put("provStatus",provStatus);
		}
		List<BaseProvince> list = sqlManager.template(BaseProvince.class,paramMap,"prov_id asc");
			//	sqlManager.select(BASE+".selectProvince",BaseProvince.class,paramMap);
		return list;
	}

	public List<BaseProvince> getValidProvinces() {
		LambdaQuery<BaseProvince> query = sqlManager.lambdaQuery(BaseProvince.class);
		return query.andEq(BaseProvince::getProvStatus,1).asc(BaseProvince::getProvId).select();
	}

	public BaseProvince getProvince(Integer provinceId) {
		return sqlManager.single(BaseProvince.class,provinceId);
	}

}
